package com.cainiao.controller;

import com.cainiao.pojo.Clazz;
import com.cainiao.pojo.ClazzQueryParam;
import com.cainiao.pojo.PageBean;
import com.cainiao.pojo.Result;
import com.cainiao.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam){
        PageBean clazz = clazzService.page(clazzQueryParam);
        return Result.success(clazz);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(clazzService.findById(id));
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        return Result.success(clazzService.findClazz());
    }
}
